package pojo;

import soot.SootClass;
import soot.SootMethod;
import soot.jimple.Stmt;

import java.io.Serializable;
import java.util.Objects;

public class MyCallsite implements Serializable {
    public Stmt stmt;
    public SootMethod method;
//    int lineNumber = -1;
    public String stmtStr;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MyCallsite callsite = (MyCallsite) o;
        return Objects.equals(stmt, callsite.stmt) && Objects.equals(method, callsite.method) && Objects.equals(stmtStr, callsite.stmtStr);
    }

    @Override
    public int hashCode() {
        return Objects.hash(stmt, method, stmtStr);
    }


    public MyCallsite(Stmt stmt, SootMethod method) {
        this.stmt = stmt;
        this.method = method;
    }

    public MyCallsite(Stmt stmt, SootMethod method, String stmtStr) {
        this.stmt = stmt;
        this.method = method;
        this.stmtStr = stmtStr;
    }

    public boolean hasValidStmt() {
        return this.stmt != null;
    }

    public SootClass getMethodClass() {
        return method.getDeclaringClass();
    }

    public SootMethod getMethod() {
        return method;
    }

    @Override
    public String toString() {
        if (stmt != null)
            return "[Callsite] " + "Method:" + method + "; Stmt:" + stmt;
        else
            return "[Callsite] " + "Method:" + method + "; Stmt:" + stmtStr;
    }
}